package com.lelv.business.route.action;

import java.util.ArrayList;
import java.util.List;

import com.lelv.business.route.bo.IRouteBo;
import com.lelv.business.route.bo.IRoutePreBo;
import com.lelv.business.route.model.Route;
import com.lelv.business.route.model.RoutePre;
import com.lelv.business.travelAgency.bo.ITravelAgencyBo;
import com.lelv.framework.action.BaseAction;
import com.lelv.framework.bo.IUserBo;
import com.lelv.framework.model.User;
import com.lelv.framework.plugin.DictUtil;
import com.lelv.framework.plugin.LelvUtils;
import com.lelv.framework.plugin.Page;

public class RoutePreAction extends BaseAction{

	private IRoutePreBo routePreBo;
	private IUserBo userBo;
	private IRouteBo routeBo;
	private ITravelAgencyBo travelAgencyBo;
	private RoutePre routePre = new RoutePre();
	private User user = new User();
	private Route route = new Route();
	private Page page = new Page();
	private List<RoutePre> routePreList = new ArrayList<RoutePre>();
	private String message = "";

	public String payRoutePre(){

		User tempUser = this.userBo.getUserById(user.getUserId());
		RoutePre tempPre = this.routePreBo.getRoutePreById(routePre.getRoutePreId());

		if(tempUser.getMoney() < route.getRoutePrice()){
			message = "余额不足，请充值";
		}else{
			Double updateUserMoney = tempUser.getMoney() - route.getRoutePrice();
			tempUser.setMoney(updateUserMoney);
			this.userBo.updateUser(tempUser);
			tempPre.setPayState(DictUtil.PAY_STATE1);
			this.routePreBo.updateRoutePre(tempPre);
			message = "支付成功";
		}

		return SUCCESS;
	}

	public String getCurrentRoutePre(){

		this.page = this.routePreBo.getRoutePrePage(page);
		this.routePreList = this.page.getList();

		return SUCCESS;
	}

	public String addRoutePre(){

		routePre.setRoutePreOrderId(LelvUtils.createOrderNo());
		this.routePreBo.addRoutePre(routePre);

		return "addOK";
	}

	public String deleteRoutePre(){

		this.routePreBo.deleteRoutePre(routePre.getRoutePreId());

		return SUCCESS;
	}

	public String deleteRoutePreForUser(){

		this.routePreBo.deleteRoutePre(user.getUserId(),route.getRouteId());

		return SUCCESS;
	}

	public IRoutePreBo getRoutePreBo() {
		return routePreBo;
	}

	public void setRoutePreBo(IRoutePreBo routePreBo) {
		this.routePreBo = routePreBo;
	}

	public RoutePre getRoutePre() {
		return routePre;
	}

	public void setRoutePre(RoutePre routePre) {
		this.routePre = routePre;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Route getRoute() {
		return route;
	}

	public void setRoute(Route route) {
		this.route = route;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public List<RoutePre> getRoutePreList() {
		return routePreList;
	}

	public void setRoutePreList(List<RoutePre> routePreList) {
		this.routePreList = routePreList;
	}

	public IUserBo getUserBo() {
		return userBo;
	}

	public void setUserBo(IUserBo userBo) {
		this.userBo = userBo;
	}

	public IRouteBo getRouteBo() {
		return routeBo;
	}

	public void setRouteBo(IRouteBo routeBo) {
		this.routeBo = routeBo;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public ITravelAgencyBo getTravelAgencyBo() {
		return travelAgencyBo;
	}

	public void setTravelAgencyBo(ITravelAgencyBo travelAgencyBo) {
		this.travelAgencyBo = travelAgencyBo;
	}

}
